package com.hz.commonLibs.utils;

import javax.xml.bind.DatatypeConverter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author LiiiYiAn
 * @version 1.0
 * @createDate 2023-09-24 13:21
 * @projectName SchoolServicePlatformFinal
 * @className StringHelper
 * @description 字符串工具类
 */
public class StringHelper {

    /**
     * @author LiiiYiAn
     * @createDate 2023/9/24 13:22
     * @description 通过MD5加密算法加密字符串
     * @param input 输入字符串
     * @return java.lang.String 加密后字符串
     **/
    public static String generateMD5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(input.getBytes());
            byte[] digest = md.digest();

            return DatatypeConverter.printHexBinary(digest);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

}
